import load

def caluDiff(x, y, startPos=1):
    result=[]
    for i in range(startPos,len(y)):
        r=(y[i-1]-y[i])/(x[i-startPos]-x[i])
        result.append(r)
    while len(result)!=len(y):
        result=[0]+result
    return result

day=list(range(load.yMax))
nationList=[]
for nation in range(1,load.xMax):
    valList=[]
    for i in range(1,load.yMax):
        val=int(load.getCell(nation,i))
        valList.append(val)
    nationList.append(valList)

for nation in range(len(nationList)):
    y1=caluDiff(day,nationList[nation])
    y2=caluDiff(day,y1,2)
    nationList[nation]=y2

import numpy as np
nationList=np.array(nationList)
print(nationList)
np.savetxt('result.csv',nationList,fmt='%d',delimiter=',')